<?php
//实现跳转
class DirectController extends Controller
{
	//api跳转
    public function actionIndex()
	{
        if(!isset($_GET['id']) || !$_GET['id']){
			$this->redirect(array('site/index'));
        }
        $id = trim($_GET['id']);
        $defaultCfg= array(
			'method' => 'taobao.taobaoke.items.convert',
			'fields' => 'click_url',
            'num_iids'=>$id,
            'timestamp'=> time(),
			'outer_code'=>'miyifun',
		);
		$api = new TaobaoApi($defaultCfg);
        $result = $api->getSingleData();      
		if(!count($result['taobaoke_items_convert_response']['taobaoke_items']['taobaoke_item'])){
			echo '没有符合条件的商品，请重新查询';
		}else{
           $url = $result['taobaoke_items_convert_response']['taobaoke_items']['taobaoke_item'][0]['click_url'];
           header("Location: $url");

           exit;
        }
	}

	//db跳转
	public function actionGoto(){
		if(!isset($_GET['iid']) || !$_GET['iid']){
			$this->redirect(array('site/index'));
        }
        $iid = trim($_GET['iid']);
		$item = Items::model()->find('num_iid=:num_iid', array(':num_iid'=>$iid));
		if($item){
			header("Location: $item->click_url");
		}else{
			echo '该商品已经下架';
		}
		exit;
	}
	//db跳转
	public function actionGoshop(){
		if(!isset($_GET['iid']) || !$_GET['iid']){
			$this->redirect(array('site/index'));
        }
        $iid = trim($_GET['iid']);
		$item = Items::model()->find('num_iid=:num_iid', array(':num_iid'=>$iid));
		if($item){
			header("Location: $item->shop_click_url");
		}else{
			echo '该商品已经下架';
		}
		exit;
	}
}